package com.crm.controller.repositoryController;

import com.crm.pojo.Inandoutlog;
import com.crm.pojo.ProductionDetail;
import com.crm.service.productionService.ProductionDetilsService;
import com.crm.service.repositoryService.ProstockService;
import com.crm.vo.ProstockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.ws.Action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ProstockController {
    @Autowired
    private ProstockService prostockService;
    @Autowired
    private ProductionDetilsService productionDetilsService;
    @GetMapping("pRepository")
    public String toProRepository(){
        return "repository/proStock";
    }
    //分页查询所有的产品库存
    @PostMapping("allproRPaged")
    @ResponseBody
    public Map allProstockPaged(int page, int rows) {
        Long total = productionDetilsService.queryCount();
        List<ProstockVO> vo = prostockService.findAll(page, rows);
        HashMap map = new HashMap<>();
        map.put("total", total);
        map.put("rows", vo);
        return map;
    }
    //模糊查询
    @PostMapping("findProstockBymh")
    @ResponseBody
    public List<ProstockVO> findProstockBymh(String q,String b){
        List<ProstockVO> prostockVOS=null;
        if(b.equals("r1")){
            prostockVOS = prostockService.findAllBymh(q);
        }
        return prostockVOS;
    }
    //跳转高级查询表单
    @GetMapping("to-form-proR-highLevel")
    public String toFormProRhighlevel(){
        return "repository/proStockhl";
    }
    //高级查询产品库存信息
    @PostMapping("ProR-form-hlq-sub")
    @ResponseBody
    public Map prostockFormhlq(ProductionDetail productionDetail, int page, int rows){
        Map map = new HashMap<>();
        Long count = productionDetilsService.proHlqCount(productionDetail);
        List<ProductionDetail> pro = productionDetilsService.proHlq(productionDetail,page,rows);
        map.put("total",count);
        map.put("rows",prostockService.dofor(pro));
        return map;
    }

}
